//获取应用实例
var app = getApp()
const _request = require("../../utils/request.js"); // 引入require;
Page({
  data: {
    banners:[],
    pendingSum: '0',
    acceptAndServiceSum: '0',
    successSum: '0',
    refundSum: '0',
    shopimgUrl: app.globalData.shopimgUrl,
    show:false,//认证蒙层
    authtype:'',//1通过 0待审核 -1驳回 3未申请认证
    isRead:1,//认证是否已读 1已读
  },
  
  // 前往详情
  toDetails(e) {
    const {
      item
    } = e.currentTarget.dataset
    if (item.title == '新人大礼包') {
      wx.navigateTo({
        url: '/pages/giftpacks/index',
      })
    } else if (item.title == '【美发店互联网意约拓客卡】199元抢购中！') {
      wx.navigateTo({
        url: '/pages/activitydetails/index?id=' + item.specialActivityId,
      })
    }else if (item.title == '商城') {
      wx.switchTab({
        url: '/firstpages/shopping/index',
      })
    }
  },
  onLoad: function (options) {
    let storeId = wx.getStorageSync('storeId');
    if (!storeId) {
      wx.navigateTo({
        url: "/pages/login/index"
      });
    }
  },
  onShow:function(){
    this.getStoreOrderStatistical();
    this.getBanners();
    this.authentication();//获取认证状态
  },
  authentication(){
    _request.get('/storeAuthApply/getStoreAuthStatusByStoreId', { storeId:wx.getStorageSync('storeId') }).then((res) => {
      console.log(res)
      if (res.data.code == 200) {
        this.setData({
          authtype:res.data.data.status,
          isRead:res.data.data.isRead,
        })
        if(this.data.authtype == 3){
          var that = this
          wx.showModal({
            title: '您还未进行信息认证',
            content: '为了完整的进行体验，请先完成信息认证再进行操作。',
            cancelText:'暂不认证',
            confirmText:'立即认证',
            success (res) {
              if (res.confirm) {
                that.goauthindex()
              }
            }
          })
        }
        if(this.data.isRead!=1 && (this.data.authtype==0 || this.data.authtype==1 || this.data.authtype==-1)){
          this.getshow()
        }
      }
    })
  },
  getshow(){
    this.setData({
      show:!this.data.show
    })
  },
  goauthindex(){
    wx.navigateTo({
      url: '/pages/auth/index',
    })
  },
  getauthbaseindex(){
    wx.navigateTo({
      url: '/pages/auth/base/index',
    })
  },
  //获取banner信息
  getBanners:function(){
    let userId = wx.getStorageSync('userId');
    _request.get('/storeBanner/getBanners', {
      userId: userId,
    }).then((res) => {
      this.setData({
        banners: res.data.data,
      })
    }).catch((error) => {
      console.log(error, 'error');
    })
  },
  // 获取门店订单信息
  getStoreOrderStatistical() {
    _request.get('/store/getStoreOrderStatistical', {
      storeId: wx.getStorageSync('storeId'),
    }).then((res) => {
      this.setData({
        pendingSum: res.data.data.pendingSum,
        acceptAndServiceSum: res.data.data.acceptAndServiceSum,
        successSum: res.data.data.successSum,
        refundSum: res.data.data.refundSum,
      })
    }).catch((error) => {
      console.log(error, 'error');
    })
  },
  onOrderListTap: function (event) {
    var orderStatus = event.currentTarget.dataset.orderStatus;
    wx.navigateTo({
      url: "/pages/orderlist/index?orderStatus=" + orderStatus
    });
  },
  onOrderTap: function () {
    wx.navigateTo({
      url: "/pages/order/index"
    });
  },
  onSeatTap: function () {
    wx.navigateTo({
      url: "/pages/seat/index"
    });
  },
  onEvaluationTap: function () {
    wx.navigateTo({
      url: "/pages/evaluation/index"
    });
  },
  onPersonTap: function () {
    wx.navigateTo({
      url: "/pages/person/index"
    });
  },
  onMarketTap: function () {
    wx.navigateTo({
      url: "/pages/market/index"
    });
  },
  onTimeTap: function () {
    wx.navigateTo({
      url: "/pages/time/index"
    });
  },
  onInvitationTap: function () {
    wx.navigateTo({
      url: "/pages/invite/index"
    });
  },
  onShopManagerTap: function () {
    wx.navigateTo({
      url: "/pages/shopmanager/index"
    });
  },
  onMyStylistsTap: function () {
    wx.navigateTo({
      url: "/pages/my_stylists/my_stylists"
    });
  }
})